﻿package com.evidencer.java.net;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Scanner;

public class UDPChatClient implements Runnable {

	@Override
	public void run() {
		//连接主机名和端口号
		String hostName="172.16.255.255";
		int port=9999;
		try{
			while(true){
				// 初始化套接字连接
				DatagramSocket dsSend=new DatagramSocket();
				
				//封装聊天数据
				Scanner sc=new Scanner(System.in);
				String sendStr=sc.next();
				
				byte[] sendBytes=sendStr.getBytes();
				
				DatagramPacket dp=new DatagramPacket(sendBytes,sendBytes.length,InetAddress.getByName(hostName),port);
				
				// 发送聊天信息
				dsSend.send(dp);
				if("88".equals(sendStr)){
					dsSend.close();
					break;
				}
			}
		}catch(Exception e){
		}
		finally{
		}
		
	}

}
